import collections


class Solution(object):
    def findDuplicate(self, paths):
        """
        :type paths: List[str]
        :rtype: List[List[str]]
        """
        d = collections.defaultdict(list)
        for path in paths:
            s = path.split(' ')
            root = s[0]
            for file in s[1:]:
                t = file.split('(', 1)
                file_name = t[0]
                content = t[1][:-1]
                d[content].append(root + '/' + file_name)
        out = []
        for key in d:
            if len(d[key]) > 1:
                out.append(d[key])
        return out


data = Solution()
paths = ["root/a 1.txt(abcd) 2.txt(efgh)", "root/c 3.txt(abcd)", "root/c/d 4.txt(efgh)", "root 4.txt(efgh)"]
print(data.findDuplicate(paths))
paths = ["root/a 1.txt(abcd) 2.txt(efgh)", "root/c 3.txt(abcd)", "root/c/d 4.txt(efgh)"]
print(data.findDuplicate(paths))
